﻿/**
 * Created by Administrator on 2018/10/8.
 */
+function ($) {
    var ExtMultiSelect = function (f, e) {
        this.$element =  $(f);
        this.options = $.extend({}, ExtMultiSelect.DEFAULTS, e);
        this.init()
    };

    ExtMultiSelect.prototype.init = function () {
        var $element = this.$element, options = $element.data().options,
            options =  (options && typeof options === 'string') ?options.toObj():options;
        options = $.extend(options,this.options);
        $element.multiSelect(options)
    }

    ExtMultiSelect.DEFAULTS = {
        selectableHeader: "可选列表", selectionHeader: "已选列表"
    }
    function Plugin(e) {
        Bolt.assert($.fn.multiSelect, "依赖组件 multiSelect 未引入");
        return this.each(function () {
            var h = $(this);
            var g = h.data("extMultiSelect");
            var f = typeof e == "object" && e;
            if (!g) {
                h.data("extMultiSelect", (g = new ExtMultiSelect(this, f)))
            }
            if (typeof e == "string") {
                g[e]()
            }
        })
    }

    $.fn.extMultiSelect = Plugin
    $.fn.extMultiSelect.Constructor = ExtMultiSelect;

    Bolt.addComponent({
        name: "ExtMultiSelect",
        plugin: Plugin,
        runPoint: Bolt.eventType.afterAjaxPageShow,
        expr: "select[data-toggle='multiSelect']",
        order: 800
    })
}(jQuery);
